﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using Tencent.OA.App;

namespace Tencent.OA.ACM.Service.Host
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main()
        {
            Sta:
            Console.WriteLine("Now Starting All Service.");
            ServiceManager.StartAllConfiguredServices();
            Console.WriteLine("Press Any Key To Close All Service.");
            Console.ReadKey();
            ServiceManager.CloseAllServices();

            Console.WriteLine("Press Any Key To Start All Service,Press ESC To Exit!");
            if (Console.ReadKey().Key == ConsoleKey.Escape)
            {
                return;
            }
            else
            {
                Console.WriteLine("-----------------------------------------------------------\r\n");
                goto Sta;
            }
            return;

            #region
            /*
            try
            {
                //全局异常处理
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    new Service1()
                };
                ServiceBase.Run(ServicesToRun);
            }
            catch (Exception ex)
            {
                LoggerProvider.CurrentLogger.Log(ex);
            }
             * */
            #endregion
        }
        /// <summary>
        /// 当前应用程序域错误处理
        /// </summary>
        /// <param name="sender">未处理的异常事件的源</param>
        /// <param name="e">包含事件数据的 UnhandledExceptionEventArgs</param>
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            if (e != null && e.ExceptionObject != null)
            {
                Exception ex = e.ExceptionObject as Exception;
                if (ex != null)
                {
                    try
                    {
                        LoggerProvider.CurrentLogger.Error(ex);
                    }
                    catch { }
                }
            }
        }

    }
}
